<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Wejin extends Admin_Controller
{
    function my_dir($dir) {
        $files = array();
        if(@$handle = opendir($dir)) { //注意这里要加一个@，不然会有warning错误提示：）
            while(($file = readdir($handle)) !== false) {
                if($file != ".." && $file != ".") { //排除根目录；
                    if(is_dir($dir."/".$file)) { //如果是子文件夹，就进行递归
                        $files[$file] = $this->my_dir($dir."/".$file);
                    } else { //不然就将文件的名字存入数组；
                        if (strstr($file, '副本')) {
                            $files[] = $file;
                        }

                    }

                }
            }
            closedir($handle);
            return $files;
        }
    }

    function dir_y()
    {
        $dir = $this->my_dir('/home/vagrant/code/product/album/new');

        foreach ($dir as $k_w => $item) {
            foreach ($item as $k => $val) {
                print_r($k);
                print_r("','");
                /*if (!file_exists('/home/vagrant/code/product/album/2088/'.$k)) {
                    mkdir ('/home/vagrant/code/product/album/2088/'.$k,0777,true);
                    foreach ($val as $k_r => $value) {
                        $_gg = str_replace(array(' ','副本', '-'), array('','',''), $value);
                        //rename('/home/vagrant/code/product/album/new/'.$k_w.'/'.$k.'/'.$value, '/home/vagrant/code/product/album/2088/'.$k.'/'.$_gg);
                    }

                }*/
            }
        }
    }

    public function dirdd()
    {
        $this->load->model('goods_model');

        $query = $this->db->from('goods_album as ga')
            ->join('goods as g', 'ga.goods_id = g.goods_id', 'left')
            ->where("goods_sn in ('WY0904','WY0903','WY0902','GW0961','GW0959','GW0935','GW0903','GW0904','CR8282','GW0960','GW0905','GW0902','GW0934','GW0933','WY0929','WY0927','WY0928','WY0931','WY0901','WY0930','GW0962','GW0973','GW0974','GW0975','GW0950','WY0945','WY0943','WY0944','GW0948','GW0947','GW0949','WY0946','WY0947','GW0942','GW0945','GW0944','GW0943','WY0942','WY0938','WY0939','WY0937','GW0946','WY0941','WY0940','GW0911','GW0972','GW0968','GW0967','GW0969','WY0916','WY0911','WY0918','WY0920','WY0919','WY0917','GW0970','GW0915','GW0912','GW0971','GW0913','GW0914','WY0912','WY0915','WY0914','WY0913','GW0916','GW0920','GW0918','GW0919','GW0917','WY0921','WY0935','WY0932','WY0905','WY0933','WY0934','GW0910','GW0966','WY0910','WY0909','WY0936','WY0907','WY0906','WY0908','GW0941','GW0940','GW0936','GW0909','GW0907','GW0938','GW0965','GW0906','GW0939','GW0937','GW0908','GW0963','GW0964','GW0898','GW0899','GW0897','RS0005','RS0004','GW0921','GW0957','GW0932','WY0898','GW0958','GW0956','GW0951','WY0899','WY0926','WY0900','RS0008','GW0924','RS0006','GW0923','GW0922','RS0007','GW0925','RS0009','GW0900','GW0954','GW0953','GW0901','GW0952','GW0955','WY0923','WY0924','WY0925','WY0922') and ga.is_delete = 0")->get();
        $goods_album = $query->result_array();

        $_al = array();
        foreach ($goods_album as $val) {
            $_al[$val['goods_sn']][] = $val['album_id'];
        }

        foreach ($_al as $k_e => $item) {
            foreach ($item as $k => $value) {
                $this->db->update('goods_album', array('original_img' => "/album/2088/{$k_e}/".($k+1).'.jpg'), "album_id = '{$value}'");
            }
        }
    }
    public function aa(){
        $page = $this->input->get('page');
        $goods_id = $this->db->from('goods')->limit(100,100*$page)->select('goods_sn,goods_id')->order_by('goods_id desc')->get()->result_array();
        // $goods_id = $this->db->from('goods')->where(['goods_sn'=>'YI2985'])->select('goods_sn,goods_id')->order_by('goods_id asc')->get()->result_array();
        // print_R($goods_id);
        foreach($goods_id as $k => $v){
            $goods_album = $this->db->from('goods_album')->where(['is_delete'=>0,'goods_id'=>$v['goods_id']])->select('original_img')->get()->result_array();
            foreach ($goods_album as $key => $val) {
                $img_info = getimagesize('http://sumerbikini.com'.$val['original_img']);
                $width = ceil($img_info[0] / 4);
                $height = ceil($img_info[1] / 5);
                $arr = [];
                $arr[] = $width;
                $arr[] = $height;
                rsort($arr);
                $val = $arr[0] - $arr[1];
                if($val > 1){
                    echo "<pre/>";
                    echo $v['goods_sn'].'------前宽'.$img_info[0].'后宽'.$width.'------前高'.$img_info[1].'后高'.$height;
                    break;
                }
            }
        }
        
    }
}
